<%--
 useage：
  <jsp:include page="/common/pg.jsp">
	<jsp:param value="${path}/xx/xx.do" name="url"/>
	<jsp:param value="${_total}" name="total"/>
	<jsp:param value="" name="urlpara"/>
  </jsp:include>
 --%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
<div class="text-right">
	<%
		int pagesize = 10;
		String paras = "";
		String totalStr = request.getParameter("total");
		String url = request.getParameter("url");
		String urlpara = request.getParameter("urlpara");
		int total = (totalStr == null || "".equals(totalStr)) ? 0 : Integer.parseInt(totalStr);

		if (urlpara != null && !"".equals(urlpara)) {
			paras = "&" + urlpara;
		}
		int totalpage = (Integer) (total % pagesize) == 0 ? (total / pagesize): (total / pagesize + 1);
	%>
	<script type="text/javascript">
	var totalPage = '<%=totalpage%>';
	var pageSize = '<%=pagesize%>';
	var url = '<%=url%>';
	var paras = '<%=paras%>';
	function goPage(){
		var inputPageValue = document.getElementById("_inputPagerNo").value;
		if(inputPageValue=='')return;
		var reg = /\d+/;
		if(!reg.test(inputPageValue)||inputPageValue<=0){
			alert("请输入大于0的数字!");
			return;
		}
		inputPageValue = Number(inputPageValue);
		
		if(inputPageValue>totalPage)inputPageValue=totalPage;
		
		var offset = (inputPageValue-1)*pageSize;
		var gourl = url+"?pg.offset="+offset+paras;
		
		self.location=gourl;
	}
	</script>
	<% if(total==0){}else{ %>
	<ul class="pagination pagination-sm">
	<pg:pager url="<%=url%>" items="<%=total %>"  isOffset="true" id="pg" export="pageOffset,currentPageNumber=pageNumber" maxPageItems="<%=pagesize %>" scope="request">
	<pg:first>
		<li><a href="<%=pageUrl+paras%>">首页</a></li>
	</pg:first>
	<pg:prev>
		<li><a href="<%=pageUrl+paras%>"><i class="icon-double-angle-left"></i> 上一页</a></li>
	</pg:prev>
	<pg:pages>
	<%if (pageNumber == currentPageNumber) {%>
	<li class="active"><a href="javascript:void(0)"><%= pageNumber %></a></li>
	<%} else {%>
	<li><a href="<%=pageUrl+paras%>"><%= pageNumber %></a></li>
	<%}%>
	
	</pg:pages>
	<pg:next>
	<li><a href="<%=pageUrl+paras%>">下一页 <i class="icon-double-angle-right"></i></a></li>
	</pg:next>
	<pg:last>
	<li><a href="<%=pageUrl+paras%>">末页</a></li>
	</pg:last>
	<li class="disabled pull-left">
  		<span style="padding:0px 8px;height:29px;line-height:29px;">
  		<input type="text" id="_inputPagerNo" style="width:48px;height:24px;line-height:24px;font-size:12px;padding:0;margin:0;"/>
  		</span>
  	</li> 
	<li><a href="javascript:void(0);" onclick="javascript:goPage()">GO</a></li>
	<li ><a href="javascript:void(0);"> 每页<%=pagesize %>条 | 共<%=totalpage%>页   | 共<%=total%>条记录</a></li>
	</pg:pager>
	</ul>
	<%} %>
</div>
